import { _decorator, Component, UIOpacity } from 'cc';
const { ccclass, disallowMultiple } = _decorator;

@ccclass('cfw.BaseUI')
@disallowMultiple
export default class BaseUI<Args extends unknown[] = any[]> extends Component {

    public get visible(): boolean { return this.node?.parent && this.node?.active; }
    public get alpha(): num.pct { return (this.getComponent(UIOpacity) ?? this.addComponent(UIOpacity)).opacity / 255; }
    public set alpha(arg: num.pct) { (this.getComponent(UIOpacity) ?? this.addComponent(UIOpacity)).opacity = 255 * arg; }
    public show(...args: Args): void { this.node.active = true; this.scheduleOnce(() => this.onShow()); }
    public hide(...args: Args): void { this.node.active = false; this.scheduleOnce(() => this.onHide()); }
    protected onShow(): void { }
    protected onHide(): void { }
}